package base.thread;

/**
 * 线程的中断
 */
public class InterrupterDemo {


    public static void main(String[] args) throws InterruptedException {
        MyThread thread=new MyThread();
        thread.start();
        Thread.sleep(2000);

        thread.interrupt();// 中断线程执行
    }

    static class MyThread extends Thread{
        int i=0;
        @Override
        public void run(){
            while (true){
                System.out.println(i);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    System.out.println("中断异常被捕获了");
                    return;
                }
                i++;
            }
        }
    }




}


